package cn.tedu.ivos.vehicle.service.impl;

import cn.tedu.ivos.base.exception.ServiceException;
import cn.tedu.ivos.base.response.StatusCode;
import cn.tedu.ivos.vehicle.mapper.RepairVehicleMapper;
import cn.tedu.ivos.vehicle.pojo.dto.RepairVehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.RepairVehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.entity.RepairVehicle;
import cn.tedu.ivos.vehicle.pojo.vo.RepairVehicleVO;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.RepairVehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author liyuehui
 * @time 2024/7/31 14:49
 */
@Slf4j
@Service
public class RepairVehicleServiceImpl implements RepairVehicleService {
    @Autowired
    RepairVehicleMapper repairVehicleMapper;

    @Override
    public List<RepairVehicleVO> select(RepairVehicleQuery repairVehicleQuery) {
        log.debug("查询维修车辆业务:repairVehicleQuery={}", repairVehicleQuery);
        List<RepairVehicleVO> list = repairVehicleMapper.selectRepairVehicle(repairVehicleQuery);
        return list;
    }

    @Override
    public void save(RepairVehicleSaveParam repairVehicleSaveParam) {
        log.debug("保存维修车辆业务:repairVehicleSaveParam={}", repairVehicleSaveParam);
        RepairVehicle repairVehicle = new RepairVehicle();
        BeanUtils.copyProperties(repairVehicleSaveParam, repairVehicle);
        if (repairVehicleSaveParam.getId() == null) {
            repairVehicle.setCreateTime(new Date());
            repairVehicleMapper.insert(repairVehicle);
            log.debug("成功插入一条维修车辆业务数据");
        } else {
            repairVehicle.setUpdateTime(new Date());
            repairVehicleMapper.update(repairVehicle);
            log.debug("成功修改维修车辆业务数据");
        }
    }

    @Override
    public void delete(Long id) {
        repairVehicleMapper.delete(id);
        log.debug("成功删除维修车辆业务数据");
    }
}
